<extend name="Console:index"/>
<block name="main">
    <!--路径导航-->
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/wangEditor-2.1.3/dist/css/wangEditor.min.css">
    <div>
        <ol class="breadcrumb">
            <li><a href="{:U('Goods/index')}">商品管理</a></li>
            <li class="active" >新增商品</li>
            <li class="active"> <a href="{$Think.server.http_referer}" class="btn btn-default btn-xs" >返回上一页</a></li>
        </ol>

    </div>
    <div style="margin-left: 10px">
        <div>
            <form class="form-horizontal" action="{:U('Goods/add')}" enctype="multipart/form-data" method="post">

                <div class="form-group">
                    <label  class=" col-sm-2 control-label" style="color:red">选择关联电影:</label>
                    <div class="col-sm-4">
                        <div class="input-group">
                            <select class="form-control" name="movie_id" id="movie_select" required>
                                <option value="" >请选择关联电影</option>
                                <volist name="movieList" id="ml" >
                                    <option value="{$ml.id}" >{$ml.id}_{$ml.name}</option>
                                </volist>
                            </select>
                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <label  class=" col-sm-2 control-label" style="color:red">选择二级目录:</label>
                    <div class="col-sm-4">
                        <div class="input-group">
                            <select class="form-control" name="movie_level2_id" id="columns" required>
                                <option value="" >请选择二级目录</option>
                            </select>
                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <label for="inputtext2" class="col-sm-2 control-label" style="color:red">品牌: </label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" id="inputtext2" name="brand" required="">
                    </div>
                </div>

                <div class="form-group">
                    <label for="inputtext1" class="col-sm-2 control-label" style="color:red">商品名称: </label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" id="inputtext1" name="name" required="">
                    </div>
                </div>


                <div class="form-group">
                    <label for="inputtext2" class="col-sm-2 control-label" style="color:red">商品标题: </label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" id="inputtext2" name="title" required="">
                    </div>
                </div>

                <div class="form-group">
                    <label for="inputtext2" class="col-sm-2 control-label" style="color:red">尺寸/鞋码: </label>
                    <div class="col-sm-4" id="div_size">
                        <div class="input-group">
                            <input type="text" class="form-control"  name="size[]" required="">
                            <div class="input-group-addon">
                                <button type="button" class=" btn btn-danger btn-xs btn_del_size" >
                                    <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
                                </button>
                            </div>
                        </div>
                    </div>

                    <button type="button" class="btn btn-success btn-sm" id="btn_size" title="增加尺寸">
                        <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
                    </button>

                </div>


                <div class="form-group">
                    <label for="inputtext2" class="col-sm-2 control-label" style="color:red">基础参数: </label>
                    <div class="col-sm-4" id="div_base">
                        <div class="input-group">
                            <input type="text" class="form-control"  name="base_key[]" required="" placeholder="参数名称">
                            <input type="text" class="form-control"  name="base_val[]" required="" placeholder="参数值">

                            <div class="input-group-addon">
                                <button type="button" class=" btn btn-danger btn-xs btn_del_base" >
                                    <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
                                </button>
                            </div>
                        </div>
                    </div>

                    <button type="button" class="btn btn-success btn-sm" id="btn_base" title="增加基础参数">
                        <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
                    </button>

                </div>


                <div class="form-group">
                    <label for="inputtext30" class="col-sm-2 control-label" style="color:red">颜色: </label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" id="inputtext30" name="color" required="">
                    </div>
                </div>

                <div class="form-group">
                    <label for="inputtext3" class="col-sm-2 control-label" style="color:red">原价: </label>
                    <div class="col-sm-4">
                        <input type="number" class="form-control" id="inputtext3" name="price" required="">
                    </div>
                </div>

                <div class="form-group">
                    <label for="inputtext3" class="col-sm-2 control-label" style="color:red">销售价格: </label>
                    <div class="col-sm-4">
                        <input type="number" class="form-control" id="inputtext3" name="sale_price" required="">
                    </div>
                </div>

                <div class="form-group">
                    <label for="inputtext100" class="  col-sm-2 control-label" style="color:red">库存:</label>
                    <div class="col-sm-4">
                        <input type="number" class="form-control" id="inputtext100" name="number" required="" value="10">
                    </div>
                </div>


                <div class="form-group">
                    <label for="inputtext22" class="  col-sm-2 control-label" style="color:red">商品剧照图片: </label>
                    <div class="col-sm-4" >
                        <input type="file" class="form-control"  name="stage_photo" required="">
                    </div>
                </div>

                <div class="form-group">
                    <label for="inputtext22" class="  col-sm-2 control-label" style="color:red">商品正方式图片: </label>
                    <div class="col-sm-4" >
                        <input type="file" class="form-control"  name="square_photo" required="">
                    </div>
                    <span>购物车,订单中使用</span>
                </div>


                <div class="form-group">
                    <label for="inputtext22" class="  col-sm-2 control-label" style="color:red">商品圆形图片: </label>
                    <div class="col-sm-4" >
                        <input type="file" class="form-control"  name="roundness_photo" required="">
                    </div>
                    <span>剧照下方圆形,分享使用</span>
                </div>


                <div class="form-group">
                    <label for="inputtext22" class="  col-sm-2 control-label" style="color:red">商品图片: </label>
                    <div class="col-sm-4" >
                        1<input type="file" class="form-control"  name="picture1" required="">
                        2<input type="file" class="form-control"  name="picture2" >
                        3<input type="file" class="form-control"  name="picture3" >
                        4<input type="file" class="form-control"  name="picture4" >
                        5<input type="file" class="form-control"  name="picture5" >
                    </div>
                    <button type="button" class=" btn btn-danger btn-sm "
                            data-container="body"
                            data-trigger="focus"
                            data-toggle="popover"
                            data-content="上传的图片至少1张,最多5张"
                            data-placement="bottom" >
                        <span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
                    </button>

                </div>


                <div class="form-group">
                    <label for="inputtext222" class="  col-sm-2 control-label" style="color:red">商品详情图片: </label>
                    <div class="col-sm-4" >
                        <textarea id="textarea1" style="height:800px;max-height:500px;"></textarea>
                    </div>
                </div>

                <div class="form-group">
                    <label for="inputtext2" class="col-sm-2 control-label" style="color:red">关联商品: </label>
                    <div class="col-sm-4" >
                       <textarea name="relevance_goods_id" id="relevance_goods_id"
                                 class="form-control" required></textarea>
                        <span style="color: red">多个id之间使用英文半角逗号分隔</span>
                    </div>
                </div>
                <input type="hidden" name="details_info" value="" id="details_info">


                <div class="form-group">
                    <label  class="col-sm-2 control-label" style="color:red">是否开启 </label>
                    <div class="col-sm-4">
                        <input type="radio" class="radio-inline"  name="status" checked value="1" >开启
                        <input type="radio" class="radio-inline"  name="status"   value="2" >下架
                    </div>
                </div>

                <input type="reset" value="重置"
                       class="btn btn-warning col-sm-offset-2   col-sm-1"/>
                <input type="submit"
                       value="保存"  id="btn_save"
                       class="btn btn-warning  col-sm-offset-1 col-sm-1"/>

            </form>

        </div>
    </div>

    <!--这里引用jquery和wangEditor.js-->
    <script type="text/javascript" src="__PUBLIC__/wangEditor-2.1.3/dist/js/wangEditor.js"></script>

    <script type="text/javascript">
        var editor = new wangEditor('textarea1');
        editor.config.uploadImgUrl = '{:U("Upload/index")}';
        editor.create();
    </script>


    <script>
        $(function(){
            //提示信息弹出
            $('[data-toggle="popover"]').popover();
            // 增加尺寸
            $('#btn_size').click(function(){
                $('#div_size').append('<div class="input-group"> ' +
                        '<input type="text" class="form-control"  name="size[]" required=""> ' +
                        '<div class="input-group-addon"> ' +
                        '<button type="button" class=" btn btn-danger btn-xs btn_del_size" > ' +
                        '<span class="glyphicon glyphicon-remove" aria-hidden="true"></span> </button> </div>');
            });

            //尺寸里面删除.
            $("#div_size").on("click",".btn_del_size",function(){
                $(this).parent().parent().empty();
            });

            // 增加基础参数
            $('#btn_base').click(function(){
                $('#div_base').append(' <div class="input-group"> ' +
                        '<input type="text" class="form-control"  name="base_key[]" required="" placeholder="参数名称"> ' +
                        '<input type="text" class="form-control"  name="base_val[]" required="" placeholder="参数值"> ' +
                        '<div class="input-group-addon"> ' +
                        '<button type="button" class=" btn btn-danger btn-xs btn_del_base" > ' +
                        '<span class="glyphicon glyphicon-remove" aria-hidden="true">' +
                        '</span> </button> </div> </div>');
            });


            //尺寸里面删除.
            $("#div_base").on("click",".btn_del_base",function(){
                $(this).parent().parent().empty();
            });



            //把
            $("#btn_save").click(function(){
                var image =  editor.$txt.html();
                $('#details_info').val(image);

                $('#')
            });

            $('#movie_select').change(function(){

                if($(this).val() != null){
                    $('#columns').empty();
                    var movie_id = $(this).val();
                    var url = "http://admin.51dy.ren/AdminV3/Movie/getMovieLevel2/movie_id/"+ movie_id+".html";

                    $.get(url,function(data){
                        if(data.status==1){
                            for (i = 0; i < data.data.length; i++) {
                                $('#columns').append('<option value="' + data.data[i].id + '">'+data.data[i].sort+'-'+data.data[i].name+'</option>');
                            }
                        }

                        if(data.status ==2){
                            $('#columns').append('<option value="" >'+data.info+'</option>');
                            //alert(data.info);
                        }

                        if(data.status ==3){
                            $('#columns').append('<option value="" >'+data.info+'</option>');
                            //alert(data.info);
                        }

                    });
                }else{
                    $('#columns').append('<option value="" >没有选择电影</option>');
                }
            });


            $("#relevance_goods_id").blur(function(){
                var num = $("#relevance_goods_id").val();
                //alert(num);
                if ("" != num){
                    if (num.indexOf("，") !=-1){
                        //alert("含有中文逗号，已经转换为英文逗号。");
                        num=num.replace(/，/ig,',');
                        $('#relevance_goods_id').val(num);

                    }
                }
            });



        })
    </script>

</block>